//
//  SignViewController.m
//  FKGW
//
//  Created by song ce on 2017/2/18.
//  Copyright © 2017年 song ce. All rights reserved.
//

#import "SignViewController.h"
#import "BaseButton.h"
@interface SignViewController ()
@property (weak, nonatomic) IBOutlet UITextField *signTextField;
@property(nonatomic,copy)NSString *str;
@end

@implementation SignViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    if(!ISNOTNEEDMESSAGEBTN){
        self.isNeedMessageItem = YES;
    }
    [self.signTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    self.signTextField.text = USERSIGNATURE;
}
- (void)textFieldDidChange:(UITextField *)textField{
    if(self.signTextField.text.length>27){
        self.signTextField.text= self.str;
        [MBProgressHUD showTipMessageInWindow:@"最多可以输入27个字符"] ;
        return;
    }
    self.str = self.signTextField.text;
}

- (IBAction)commitbtn:(BaseButton *)sender {
    if(!_str.length){
        [MBProgressHUD showTipMessageInView:@"请输入内容"];
        return;
    }
   // 2.49更改个性签名
    NSDictionary *paraDic = @{
                              @"userId":USERID,
                              @"signature":_str
                              };
    __weak typeof( self) weakSelf= self;
    [Tools AFNetworkingRequestTypePostWithUrl:CHANGESIGNATURE paramters:paraDic  afterResultBlock:^(NSDictionary *resultDic) {
        DLog(@"更改个性签名-----%@",resultDic);
        if([resultDic[@"flag"] isEqualToString:@"true"]){
            NSDictionary *dataDic = resultDic[@"data"];
            if([dataDic isKindOfClass:[NSNull class]]){
                return ;
            }
            if([dataDic[@"status"] isEqualToString:@"true"]){
                if(![AppDelegate appDealegate].isFirstSetSignature){
                      [MBProgressHUD showTipMessageInWindow:@"个性签名设置成功"];
                }else{
                        [MBProgressHUD showTipMessageInWindow:@"个性签名修改成功"];
                }
                [weakSelf performSelector:@selector(popToSettingVc) withObject:nil afterDelay:1];
            }else{
                [MBProgressHUD showTipMessageInWindow:dataDic[@"errorString"]];
            }
        }
    }];
}

-(void)popToSettingVc{
    [self.navigationController popViewControllerAnimated:YES];
}
@end
